package com.bjqg.bjqg01.bjqg.activity.longrange.utils;

import com.bjqg.bjqg01.bjqg.activity.longrange.bean.ContentBean;
import com.bjqg.greendao.ContentBeanDao;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by bjqg01 on 2018/9/3.
 */

public class ContentBeanDaoUtils {

    //查询Id的数据
    public static String getuserById(long key) {
        ContentBean user = getUserDao().load(key);
        return user.getId() + "," + user.getNumber() + "," + user.getUnit() + "," + user.getConsignor() + "," + user.getConsignorphone() +
                "," + user.getProjectname() + "," + user.getPart() + "," + user.getBreed() + "," + user.getGrade() + "," + user.getNorm() + "," + user.getVender() +
                "," + user.getCredential() + "," + user.getBrand() + "," + user.getTextitem() + "," + user.getIsziqu() + "," + user.getIsyouji() +
                "," + user.getName() + "," + user.getPhone() + "," + user.getAddress() + "," + user.getIsjzqy();
    }

    //插入数据
    public static void insertdata(String number, String unit, String consignor, String consignorphone, String projectname, String part,
                                  String breed, String grade, String norm, String vender, String credential, String brand, String textitem, boolean isziqu,
                                  boolean isyouji, String name, String phone, String address, boolean isjzqy) {

        ContentBean insertData = new ContentBean(null, number, unit, consignor, consignorphone, projectname, part, breed, grade, norm, vender, credential,
                brand, textitem, isziqu, isyouji, name, phone, address, isjzqy);
        getUserDao().insert(insertData);
    }

    //根据ID更改数据
    public static void updatadata(int key, String number, String unit, String consignor, String consignorphone, String projectname, String part,
                                  String breed, String grade, String norm, String vender, String credential, String brand, String textitem, boolean isziqu,
                                  boolean isyouji, String name, String phone, String address, boolean isjzqy) {
        List<ContentBean> userss = getUserDao().loadAll();
        ContentBean user = new ContentBean(userss.get(key).getId(), number, unit, consignor, consignorphone, projectname, part, breed, grade, norm, vender, credential,
                brand, textitem, isziqu, isyouji, name, phone, address, isjzqy);
        getUserDao().update(user);
    }

    //查询所有数据
    public static List<ContentBean> querydata() {
        //查询数据详细
        List<ContentBean> users = getUserDao().loadAll();
        return users;
    }


    /**
     * 删除所有数据
     */
    public static void deleteAllNote() {
        getUserDao().deleteAll();
    }

    /**
     * 根据用户类,删除信息
     *
     * @param user 用户信息类
     */
    public static void deleteNote(ContentBean user) {
        getUserDao().delete(user);
    }


    private static ContentBeanDao getUserDao() {
        return ContentBeanDaoManager.getInstance().getSession().getContentBeanDao();
    }
}
